package com.sddongyun.common.utils;

import com.sddongyun.common.JaxWsDynamicClientFactory;
import com.sddongyun.config.ProxConfig;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

/**
 * @author Lenovo
 * @date 2021-05-2115:44
 */
public class WJqueryUtils {


    static JaxWsDynamicClientFactory clientFactory= JaxWsDynamicClientFactory.newInstance();

    static Client client;


    public static void main(String[] args) throws Exception {
        String input = "<Request><TradeCode>90008</TradeCode><Alias>amxl</Alias></Request>";
        queryWJ("GetMedPrice", input);
    }

    /**
     * 查询物价
     * @throws Exception
     */
    public static String queryWJ(String methodName, String input) throws Exception {
//                          http://192.168.96.101/dthealth/web/QryInterface.BS.QueryService.cls?wsdl
        String targetUri = "http://192.168.96.101/dthealth/web/QryInterface.BS.QueryService.cls?wsdl";
        client=clientFactory.createClient(targetUri);

        HTTPConduit conduit=(HTTPConduit)client.getConduit();
        HTTPClientPolicy policy=new HTTPClientPolicy();
        policy.setConnectionTimeout(30000);
        policy.setReceiveTimeout(30000);
        policy.setConnectionRequestTimeout(30000);
        conduit.setClient(policy);


        input = "<Request><TradeCode>90008</TradeCode><Alias>amxl</Alias></Request>";
        Object[] response=null;
        client.getEndpoint().getEndpointInfo().setAddress(targetUri.replace("?wsdl",""));
        response= client.invoke("GetMedPrice",input);
        String out = response[0].toString();
        System.out.println("输出："+out);

        return out;

    }
}
